
import React, { Component } from 'react';
import eventBus from "@/utils/eventBus";

export default class Son extends Component {

  state={
    count:3
  }

  componentDidMount(){
    eventBus.subscribe("onChuan",(inc)=>{
      console.log("onChuan");
      this.setState({
        count:this.state.count+inc
      })
    });
  }

  componentWillUnmount(){
    eventBus.unsubscribe("onChuan");
  }

  render() {
    return (
      <div>
        <h1>子组件B</h1>
        <p>count:{this.state.count}</p>
      </div>
    )
  }
}